<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

/**
 * 模型数据管理控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class VipController extends ThinkController{
    public function vipinfo($uid){
        $re_viprecord = M('viprecord')->where(array('uid'=>$uid))->find();
        $re_viporder = M('vip_order')
        ->field('vip_order.*,membership.title as membership_title')
        ->where(array('visitor_id'=>$uid,'vip_order.status'=>1))
        ->join('membership on membership.id = vip_order.vip_type','left')
        ->order('end_time desc')
        ->find();
        if(time()<=$re_viporder['end_time']){
            $valid = '（有效期内）';
        }else{
            $valid = '（已失效）';
        }
        $reback = '会员姓名：'.$re_viprecord['name'].'，会员卡类型：'.$re_viporder['membership_title'].'，会员卡有效期：'.date('Y-m-d',$re_viporder['end_time']).$valid;
        return $reback;
    }

	public function codeCheck(){
        $vipcode = $_GET['code'];
        if(!$vipcode){
            $this->ajaxReturn('vip会员码不可为空');
        }
        $re_vip_user = M('visitor')->where(array('vipcode'=>$vipcode))->find();
        $re_user = M('visitor')->find($vipcode);
        if($re_vip_user){
            $reback = $this->vipinfo($re_vip_user['id']);
            $this->ajaxReturn($reback);
        }else if($re_user){
            if($re_user['vipcode']){
                $reback = $this->vipinfo($re_user['id']);
                $this->ajaxReturn($reback);
            }else{
                $this->ajaxReturn('该用户为普通会员');
            }
        }else{
            $this->ajaxReturn('该用户为普通会员');
        }
        
    }
	
}